home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / irit / windows.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-08  |  27.6 KB  |  692 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d (not only polygonal) solid modeller.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Module to handle the windows used by the solid modeller.             *
  7. *****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include "program.h"
  13. #include "irit_soc.h"
  14. #include "iritprsr.h"
  15. #include "windows.h"
  16. #ifdef DJGCC
  17. #include "iritgrap.h"
  18. #endif /* DJGCC */
  19.  
  20. #define IRIT_PROMPT    "Irit> "
  21. #define MAX_NUM_OF_IO_HANDLES    50
  22.  
  23. typedef struct IOHandlesStruct {
  24.     int Input, Output;
  25.     int InUse;
  26. } IOHandlesStruct;
  27. static IOHandlesStruct IOHandles[MAX_NUM_OF_IO_HANDLES];
  28.  
  29. /*****************************************************************************
  30. * DESCRIPTION:                                                               M
  31. * Routine to toggle the input window log file printing. If turned on, test   M
  32. * is made if file has been opened and if not open it.                 M
  33. *                                                                            *
  34. * PARAMETERS:                                                                M
  35. *   Set:       TRUE for log file active, FALSE inactive, or string name      M
  36. *           for a new logfile name.                         M
  37. *                                                                            *
  38. * RETURN VALUE:                                                              M
  39. *   void                                                                     M
  40. *                                                                            *
  41. * KEYWORDS:                                                                  M
  42. *   WndwLogPrint                                                             M
  43. *****************************************************************************/
  44. void WndwLogPrint(IPObjectStruct *SetObj)
  45. {
  46.     char s[LINE_LEN];
  47.  
  48.     if (IP_IS_NUM_OBJ(SetObj)) {
  49.     int Set = REAL_TO_INT(SetObj -> U.R);
  50.  
  51.     if (Set) {
  52.         if (GlblLogFile == NULL) {        /* Not open yet - open it now: */
  53.         if ((GlblLogFile = fopen(GlblLogFileName, "w")) == NULL) {
  54.             sprintf(s, "Failed to open log file \"%s\"",
  55.                 GlblLogFileName);
  56.             WndwInputWindowPutStr(s);
  57.             return;
  58.         }
  59.         GlblPrintLogFile = TRUE;
  60.         }
  61.     }
  62.     else {
  63.         GlblPrintLogFile = FALSE;
  64.         fflush(GlblLogFile);
  65.     }
  66.     }
  67.     else if (IP_IS_STR_OBJ(SetObj)) {
  68.     GlblPrintLogFile = FALSE;
  69.     if (GlblLogFile != NULL) {
  70.         fclose(GlblLogFile);
  71.         GlblLogFile = NULL;
  72.     }
  73.     if (strlen(GlblLogFileName) > 0)
  74.         IritFree(GlblLogFileName);
  75.     GlblLogFileName = IritStrdup(SetObj -> U.Str);
  76.     }
  77. }
  78.  
  79. /*****************************************************************************
  80. * DESCRIPTION:                                                               M
  81. * Routine to handle the text on the Input Window. This window echoes all     M
  82. * the input steam - the input parser input. Errors or information are also   M
  83. * calling this function.                             M
  84. *                                                                            *
  85. * PARAMETERS:                                                                M
  86. *   Msg:        To print to stdout.                                          M
  87. *                                                                            *
  88. * RETURN VALUE:                                                              M
  89. *   void                                                                     M
  90. *                                                                            *
  91. * KEYWORDS:                                                                  M
  92. *   WndwInputWindowPutStr                                                    M
  93. *****************************************************************************/
  94. void WndwInputWindowPutStr(char *Msg)
  95. {
  96.     char str[INPUT_LINE_LEN];
  97.  
  98. #if defined(__UNIX__) || defined(OS2GCC) || defined(__WINNT__) || defined(AMIGA)
  99.     /* No filtering - what we get is what is printed. */
  100.     strcpy(str, Msg);
  101. #else
  102.     int i;
  103.  
  104.     for (i = 0; *Msg != 0; Msg++) {
  105.     if (*Msg == 0x09)
  106.         do {
  107.         str[i++] = ' ';
  108.         }
  109.         while (i % 8 != 0);
  110. #ifdef AMIGA
  111.     else if (abs(*Msg) < ' ' || (abs(*Msg) > '~' && abs(*Msg) <0xA0))
  112. #else
  113.     else if (*Msg < ' ' || *Msg > '~')
  114. #endif
  115.         break;
  116.     else
  117.         str[i++] = *Msg;
  118.     }
  119.     str[i] = 0;
  120. #endif /* __UNIX__ || OS2GCC || __WINNT */
  121.  
  122.     if (GlblPrintLogFile)
  123.     fprintf(GlblLogFile, "%s\n", str);
  124.  
  125. #ifdef DJGCC
  126.     if (GlblDoGraphics) {
  127.     IntrPrintf(IGGlblInputWindowID, TRUE, str);
  128.     }
  129.     else {
  130.     printf("%s\n", str);
  131.     fflush(stdout);
  132.     }
  133. #else
  134.     if (str[strlen(str) - 1] == '\n')
  135.     printf("%s", str);
  136.     else
  137.     printf("%s\n", str);
  138.     fflush(stdout);
  139. #endif /* DJGCC */
  140. }
  141.  
  142. /*****************************************************************************
  143. * DESCRIPTION:                                                               M
  144. * Same as WndwInputWindowPutStr but does not put a new line if have none.    M
  145. *                                                                            *
  146. * PARAMETERS:                                                                M
  147. *   Msg:        To print to stdout.                                          M
  148. *                                                                            *
  149. * RETURN VALUE:                                                              M
  150. *   void                                                                     M
  151. *                                                                            *
  152. * KEYWORDS:                                                                  M
  153. *   WndwInputWindowPutStr2                                                   M
  154. *****************************************************************************/
  155. void WndwInputWindowPutStr2(char *Msg)
  156. {
  157.     char str[INPUT_LINE_LEN];
  158.  
  159. #if defined(__UNIX__) || defined(OS2GCC) || defined(__WINNT__) || defined(AMIGA)
  160.     /* No filtering - what we get is what is printed. */
  161.     strcpy(str, Msg);
  162. #else
  163.     int i;
  164.  
  165.     for (i = 0; *Msg != 0; Msg++) {
  166.     if (*Msg == 0x09)
  167.         do {
  168.         str[i++] = ' ';
  169.         }
  170.         while (i % 8 != 0);
  171. #ifdef AMIGA
  172.     else if (abs(*Msg) < ' ' || (abs(*Msg) > '~' && abs(*Msg) <0xA0))
  173. #else
  174.     else if (*Msg < ' ' || *Msg > '~')
  175. #endif
  176.         break;
  177.     else
  178.         str[i++] = *Msg;
  179.     }
  180.     str[i] = 0;
  181. #endif /* __UNIX__ || OS2GCC || __WINNT */
  182.  
  183.     if (GlblPrintLogFile)
  184.     fprintf(GlblLogFile, "%s\n", str);
  185.  
  186. #ifdef DJGCC
  187.     if (GlblDoGraphics) {
  188.     IntrPrintf(IGGlblInputWindowID, TRUE, str);
  189.     }
  190.     else {
  191.     printf("%s\n", str);
  192.     fflush(stdout);
  193.     }
  194. #else
  195.     printf("%s", str);
  196.     fflush(stdout);
  197. #endif /* DJGCC */
  198. }
  199.  
  200. /*****************************************************************************
  201. * DESCRIPTION:                                                               M
  202. * Routine to handle reading one line from stdin into string Str, with        M
  203. * maximum of length Length in the Input Window.                     M
  204. *                                                                            *
  205. * PARAMETERS:                                                                M
  206. *   Str:        Where input is placed at.                                    M
  207. *   Length:     Maximum length of input to allow.                            M
  208. *                                                                            *
  209. * RETURN VALUE:                                                              M
  210. *   void                                                                     M
  211. *                                                                            *
  212. * KEYWORDS:                                                                  M
  213. *   WndwInputWindowGetStr                                                    M
  214. *****************************************************************************/
  215. void WndwInputWindowGetStr(char *Str, int Length)
  216. {
  217. #ifdef DJGCC
  218.     if (GlblDoGraphics) {
  219.     Str[0] = 0;
  220.         IntrGetLineWindow(IGGlblInputWindowID, Str, Length);
  221.     }
  222.     else {
  223.     printf(IRIT_PROMPT);
  224.     fgets(Str, Length - 1, stdin);
  225.     if (feof(stdin))
  226.         IritExit(0);       /* Eof typed on keyboard (usually CtrlD). */
  227.     if (Str[strlen(Str) - 1] < ' ')
  228.         Str[strlen(Str) - 1] = 0;                /* No CR/LF. */
  229.     puts(Str);
  230.     fflush(stdout);
  231.     } 
  232. #else
  233.     printf(IRIT_PROMPT);
  234.     fgets(Str, Length - 1, stdin);
  235.     if (feof(stdin))
  236.     IritExit(0);           /* Eof typed on keyboard (usually CtrlD). */
  237.     if (Str[strlen(Str) - 1] < ' ') 
  238.     Str[strlen(Str) - 1] = 0;                /* No CR/LF. */
  239.     puts(Str);
  240.     fflush(stdout);
  241. #endif /* DJGCC */
  242. }
  243.  
  244. /*****************************************************************************
  245. * DESCRIPTION:                                                               M
  246. * Routine to handle reading one line from stdin into a object of type Type.  M
  247. *                                                                            *
  248. * PARAMETERS:                                                                M
  249. *   Type:      Type of object requested.                                     M
  250. *                                                                            *
  251. * RETURN VALUE:                                                              M
  252. *   IPObjectStruct *:   An object of type Type initialized from data from    M
  253. *                       stdin.                                               M
  254. *                                                                            *
  255. * KEYWORDS:                                                                  M
  256. *   WndwInputStdinObject                                                     M
  257. *****************************************************************************/
  258. IPObjectStruct *WndwInputStdinObject(RealType *Type)
  259. {
  260.     char Str[LINE_LEN];
  261.     RealType R, Pt[3];
  262.     IPObjectStruct *PObj;
  263.     IPObjStructType
  264.     IType = REAL_PTR_TO_INT(Type);
  265.  
  266. #ifdef DJGCC
  267.     if (GlblDoGraphics) {
  268.     Str[0] = 0;
  269.         IntrGetLineWindow(IGGlblInputWindowID, Str, LINE_LEN);
  270.     }
  271.     else {
  272.     fgets(Str, LINE_LEN - 1, stdin);
  273.     if (feof(stdin))
  274.         IritExit(0);       /* Eof typed on keyboard (usually CtrlD). */
  275.     if (Str[strlen(Str) - 1] < ' ')
  276.         Str[strlen(Str) - 1] = 0;                /* No CR/LF. */
  277.     } 
  278. #else
  279.     fgets(Str, LINE_LEN - 1, stdin);
  280.     if (feof(stdin))
  281.     IritExit(0);           /* Eof typed on keyboard (usually CtrlD). */
  282.     if (Str[strlen(Str) - 1] < ' ') 
  283.     Str[strlen(Str) - 1] = 0;                /* No CR/LF. */
  284. #endif /* DJGCC */
  285.  
  286. #ifdef DOUBLE
  287.     switch (IType) {
  288.     case IP_OBJ_NUMERIC:
  289.         if (sscanf(Str, "%lf", &R) == 1)
  290.         return GenNUMObject(&R);
  291.         break;
  292.     case IP_OBJ_POINT:
  293.         if (sscanf(Str, "%lf %lf %lf", &Pt[0], &Pt[1], &Pt[2]) == 3 ||
  294.         sscanf(Str, "%lf,%lf,%lf", &Pt[0], &Pt[1], &Pt[2]) == 3)
  295.         return GenPTObject(&Pt[0], &Pt[1], &Pt[2]);
  296.         break;
  297.     case IP_OBJ_VECTOR:
  298.         if (sscanf(Str, "%lf %lf %lf", &Pt[0], &Pt[1], &Pt[2]) == 3 ||
  299.         sscanf(Str, "%lf,%lf,%lf", &Pt[0], &Pt[1], &Pt[2]) == 3)
  300.         return GenVECObject(&Pt[0], &Pt[1], &Pt[2]);
  301.         break;
  302.     case IP_OBJ_PLANE:
  303.         if (sscanf(Str, "%lf %lf %lf %lf",
  304.                &Pt[0], &Pt[1], &Pt[2], &Pt[3]) == 4 ||
  305.         sscanf(Str, "%lf,%lf,%lf,%lf",
  306.                &Pt[0], &Pt[1], &Pt[2], &Pt[3]) == 4)
  307.         return GenPLANEObject(&Pt[0], &Pt[1], &Pt[2], &Pt[3]);
  308.         break;
  309.     default:
  310.         break;
  311.     }
  312. #else
  313.     switch (IType) {
  314.     case IP_OBJ_NUMERIC:
  315.         if (sscanf(Str, "%f", &R) == 1)
  316.         return GenNUMObject(&R);
  317.         break;
  318.     case IP_OBJ_POINT:
  319.         if (sscanf(Str, "%f %f %f", &Pt[0], &Pt[1], &Pt[2]) == 3 ||
  320.         sscanf(Str, "%f,%f,%f", &Pt[0], &Pt[1], &Pt[2]) == 3)
  321.         return GenPTObject(&Pt[0], &Pt[1], &Pt[2]);
  322.         break;
  323.     case IP_OBJ_VECTOR:
  324.         if (sscanf(Str, "%f %f %f", &Pt[0], &Pt[1], &Pt[2]) == 3 ||
  325.         sscanf(Str, "%f,%f,%f", &Pt[0], &Pt[1], &Pt[2]) == 3)
  326.         return GenVECObject(&Pt[0], &Pt[1], &Pt[2]);
  327.         break;
  328.     case IP_OBJ_PLANE:
  329.         if (sscanf(Str, "%f %f %f %f",
  330.                &Pt[0], &Pt[1], &Pt[2], &Pt[3]) == 4 ||
  331.         sscanf(Str, "%f,%f,%f,%f",
  332.                &Pt[0], &Pt[1], &Pt[2], &Pt[3]) == 4)
  333.         return GenPLANEObject(&Pt[0], &Pt[1], &Pt[2], &Pt[3]);
  334.         break;
  335.     default:
  336.         break;
  337.     }
  338. #endif /* DOUBLE */
  339.  
  340.     PObj = IPAllocObject("", IP_OBJ_STRING, NULL);
  341.     PObj -> U.Str = IritStrdup(Str);
  342.     return PObj;
  343. }
  344.  
  345. /*****************************************************************************
  346. * DESCRIPTION:                                                               M
  347. *   Sets the display device channel.                         M
  348. *                                                                            *
  349. * PARAMETERS:                                                                M
  350. *   None                                                                     M
  351. *                                                                            *
  352. * RETURN VALUE:                                                              M
  353. *   void                                                                     M
  354. *                                                                            *
  355. * KEYWORDS:                                                                  M
  356. *   WndwViewSetDisplay                                                       M
  357. *****************************************************************************/
  358. void WndwViewSetDisplay(void)
  359. {
  360.     char
  361.     *Program = getenv("IRIT_DISPLAY");
  362.  
  363.     if (!GlblDoGraphics)
  364.     return;
  365.  
  366.     if (!IritPrsrSrvrExecAndConnect(Program,
  367.                     &GlblDisplayDeviceInput,
  368.                     &GlblDisplayDeviceOutput,
  369.                     getenv("IRIT_BIN_IPC") != NULL))
  370.     {
  371.     fprintf(stderr, "Failed to execute display device \"%s\"\n",
  372.         Program == NULL ? "?" : Program);
  373.     exit(0);
  374.     }
  375. }
  376.  
  377. /*****************************************************************************
  378. * DESCRIPTION:                                                               M
  379. * Display one object on display device.                         M
  380. *                                                                            *
  381. * PARAMETERS:                                                                M
  382. *   PObj:      Object to display.                                            M
  383. *                                                                            *
  384. * RETURN VALUE:                                                              M
  385. *   void                                                                     M
  386. *                                                                            *
  387. * KEYWORDS:                                                                  M
  388. *   WndwViewObject                                                           M
  389. *****************************************************************************/
  390. void WndwViewObject(IPObjectStruct *PObj)
  391. {
  392.     if (!GlblDoGraphics)
  393.     return;
  394.  
  395.     if (GlblDisplayDeviceInput < 0 || GlblDisplayDeviceOutput < 0)
  396.     WndwViewSetDisplay();
  397.  
  398.     if (IP_IS_STR_OBJ(PObj)) {
  399.     if (GlblDisplayDeviceInput < 0)
  400.         return;
  401.  
  402.     if (strcmp(PObj -> Name, "COMMAND_") == 0 &&
  403.         (strcmp(PObj -> U.Str, "EXIT") == 0 ||
  404.          strcmp(PObj -> U.Str, "DISCONNECT") == 0)) {
  405.         IritPrsrSrvrKillAndDisConnect(strcmp(PObj -> U.Str, "EXIT") == 0,
  406.                       GlblDisplayDeviceInput,
  407.                       GlblDisplayDeviceOutput);
  408.         GlblDisplayDeviceInput = GlblDisplayDeviceOutput = -1;
  409.     }
  410.     else
  411.         SocWriteOneObject(GlblDisplayDeviceInput, PObj);
  412.     }
  413.     else
  414.     SocWriteOneObject(GlblDisplayDeviceInput, PObj);
  415. }
  416.  
  417. /*****************************************************************************
  418. * DESCRIPTION:                                                               M
  419. * Clears the display device's device.                         M
  420. *                                                                            *
  421. * PARAMETERS:                                                                M
  422. *   None                                                                     *
  423. *                                                                            *
  424. * RETURN VALUE:                                                              M
  425. *   void                                                                     M
  426. *                                                                            *
  427. * KEYWORDS:                                                                  M
  428. *   WndwViewClearScreen                                                      M
  429. *****************************************************************************/
  430. void WndwViewClearScreen(void)
  431. {
  432.     IPObjectStruct
  433.     *PObj = IPAllocObject("COMMAND_", IP_OBJ_STRING, NULL);
  434.  
  435.     strcpy(PObj -> U.Str, "CLEAR");
  436.     if (GlblDisplayDeviceInput >= 0)
  437.     WndwViewObject(PObj);
  438.     IPFreeObject(PObj);
  439. }
  440.  
  441. /*****************************************************************************
  442. * DESCRIPTION:                                                               M
  443. * Asks the display device to save its current transformation matrix in       M
  444. * file FileName.                                                             M
  445. *                                                                            *
  446. * PARAMETERS:                                                                M
  447. *   FileName:   Name of file to save current transformation.                 M
  448. *                                                                            *
  449. * RETURN VALUE:                                                              M
  450. *   void                                                                     M
  451. *                                                                            *
  452. * KEYWORDS:                                                                  M
  453. *   WndwViewSaveMatrix                                                       M
  454. *****************************************************************************/
  455. void WndwViewSaveMatrix(char *FileName)
  456. {
  457.     IPObjectStruct
  458.     *PObj = IPAllocObject("COMMAND_", IP_OBJ_STRING, NULL);
  459.  
  460.     sprintf(PObj -> U.Str, "MSAVE %s", FileName);
  461.     if (GlblDisplayDeviceInput >= 0)
  462.     WndwViewObject(PObj);
  463.     IPFreeObject(PObj);
  464. }
  465.  
  466. /*****************************************************************************
  467. * DESCRIPTION:                                                               M
  468. * Disconnect from current display device but dont ask it t quit.         M
  469. *                                                                            *
  470. * PARAMETERS:                                                                M
  471. *   None                                                                     *
  472. *                                                                            *
  473. * RETURN VALUE:                                                              M
  474. *   void                                                                     M
  475. *                                                                            *
  476. * KEYWORDS:                                                                  M
  477. *   WndwViewDisconnect                                                       M
  478. *****************************************************************************/
  479. void WndwViewDisconnect(void)
  480. {
  481.     IPObjectStruct
  482.     *PObj = IPAllocObject("COMMAND_", IP_OBJ_STRING, NULL);
  483.  
  484.     strcpy(PObj -> U.Str, "DISCONNECT");
  485.     if (GlblDisplayDeviceInput >= 0)
  486.     WndwViewObject(PObj);
  487.     IPFreeObject(PObj);
  488. }
  489.  
  490. /*****************************************************************************
  491. * DESCRIPTION:                                                               M
  492. * Disconnect from current display device and ask it to terminate.         M
  493. *                                                                            *
  494. * PARAMETERS:                                                                M
  495. *   None                                                                     *
  496. *                                                                            *
  497. * RETURN VALUE:                                                              M
  498. *   void                                                                     M
  499. *                                                                            *
  500. * KEYWORDS:                                                                  M
  501. *   WndwViewExit                                                             M
  502. *****************************************************************************/
  503. void WndwViewExit(void)
  504. {
  505.     IPObjectStruct
  506.     *PObj = IPAllocObject("COMMAND_", IP_OBJ_STRING, NULL);
  507.  
  508.     /* The second exit should fail on write closing the connection locally. */
  509.     strcpy(PObj -> U.Str, "EXIT");
  510.  
  511.     if (GlblDisplayDeviceInput >= 0)
  512.     WndwViewObject(PObj);
  513.  
  514.     IPFreeObject(PObj);
  515.  
  516. }
  517.  
  518. /*****************************************************************************
  519. * DESCRIPTION:                                                               M
  520. *   Executes the program named PrgmName as a subprocess and hook a           M
  521. * bidirectional communication channel between this IRIT server and PrgmName. M
  522. *                                                                            *
  523. * PARAMETERS:                                                                M
  524. *   PrgmName:   To execute as a subprocess.                                  M
  525. *                                                                            *
  526. * RETURN VALUE:                                                              M
  527. *   RealType:   A handle to the input/output channel.                        M
  528. *                                                                            *
  529. * KEYWORDS:                                                                  M
  530. *   ClientExecute, ipc                                                       M
  531. *****************************************************************************/
  532. RealType ClientExecute(char *PrgmName)
  533. {
  534.     int Input = -1,
  535.     Output = -1;
  536.  
  537.     if (IritPrsrSrvrExecAndConnect(PrgmName, &Input, &Output,
  538.                    getenv("IRIT_BIN_IPC") != NULL) &&
  539.     Input >= 0 &&
  540.     Output >= 0) {
  541.     int i;
  542.  
  543.     for (i = 0; i < MAX_NUM_OF_IO_HANDLES; i++) {
  544.         if (!IOHandles[i].InUse) {
  545.         IOHandles[i].Input = Input;
  546.         IOHandles[i].Output = Output;
  547.         IOHandles[i].InUse = TRUE;
  548.         return i;
  549.         }
  550.     }
  551.     IritPrsrFatalError("Not enough client handlers, exec failed");
  552.     return -1;
  553.     }
  554.     else {
  555.     IritPrsrFatalError("Failed to execute program, exec failed");
  556.     return -1;
  557.     }
  558. }
  559.  
  560. /*****************************************************************************
  561. * DESCRIPTION:                                                               M
  562. *   Close a connection to a client subprocess specified by Handler.          M
  563. *                                                                            *
  564. * PARAMETERS:                                                                M
  565. *   RHandler:    Valid subprocess handler.                                   M
  566. *   KillClient:  If TRUE, a request for the client to die is sent.         M
  567. *                                                                            *
  568. * RETURN VALUE:                                                              M
  569. *   void                                                                     M
  570. *                                                                            *
  571. * KEYWORDS:                                                                  M
  572. *   ClientClose, ipc                                                         M
  573. *****************************************************************************/
  574. void ClientClose(RealType *RHandler, int KillClient)
  575. {
  576.     int Handler = REAL_PTR_TO_INT(RHandler);
  577.  
  578.     if (Handler >= 0 &&
  579.     Handler < MAX_NUM_OF_IO_HANDLES &&
  580.     IOHandles[Handler].InUse) {
  581.     IritPrsrSrvrKillAndDisConnect(KillClient,
  582.                       IOHandles[Handler].Input,
  583.                       IOHandles[Handler].Output);
  584.     IOHandles[Handler].InUse = FALSE;
  585.     }
  586.     else
  587.     IritPrsrFatalError("Invalid communication handler");
  588. }
  589.  
  590. /*****************************************************************************
  591. * DESCRIPTION:                                                               M
  592. *   Close a connection to all active clients.                         M
  593. *                                                                            *
  594. * PARAMETERS:                                                                M
  595. *   KillClient:  If TRUE, a request for the client to die is sent.         M
  596. *                                                                            *
  597. * RETURN VALUE:                                                              M
  598. *   void                                                                     M
  599. *                                                                            *
  600. * KEYWORDS:                                                                  M
  601. *   ClientCloseAll, ipc                                                      M
  602. *****************************************************************************/
  603. void ClientCloseAll(int KillClient)
  604. {
  605.     int i;
  606.  
  607.     for (i = 0; i < MAX_NUM_OF_IO_HANDLES; i++) {
  608.     if (IOHandles[i].InUse) {
  609.         RealType
  610.         R = i;
  611.  
  612.         ClientClose(&R, KillClient);
  613.     }
  614.     }
  615. }
  616.  
  617. /*****************************************************************************
  618. * DESCRIPTION:                                                               M
  619. *   Read one object from subprocess's input channel specified by Handler.    M
  620. *                                                                            *
  621. * PARAMETERS:                                                                M
  622. *   RHandler:  Valid subprocess handler.                                     M
  623. *   Block:     If positive, blocks at most that much time if no object.      M
  624. *                                                                            *
  625. * RETURN VALUE:                                                              M
  626. *   IPObjectStruct *:   One read object. If timeout, a string object is      M
  627. *            returned with content of "No data (timeout)".        M
  628. *                                                                            *
  629. * KEYWORDS:                                                                  M
  630. *   ClientRead, ipc                                                          M
  631. *****************************************************************************/
  632. IPObjectStruct *ClientRead(RealType *RHandler, RealType *RBlock)
  633. {
  634.     int Handler = REAL_PTR_TO_INT(RHandler),
  635.     Block = REAL_PTR_TO_INT(RBlock);
  636.     IPObjectStruct
  637.     *PObj = NULL;
  638.  
  639.     if (Handler >= 0 &&
  640.     Handler < MAX_NUM_OF_IO_HANDLES &&
  641.     IOHandles[Handler].InUse) {
  642.     do {
  643.         PObj = SocReadOneObject(IOHandles[Handler].Output);
  644.  
  645.         /* Sleep 10 miliseconds at a time, if no data. */
  646.         if (PObj == NULL) {
  647.         Block -= 10;
  648.         if (Block > 10)
  649.             IritSleep(10);
  650.         }
  651.         else
  652.         Block = 0;
  653.     }
  654.     while (Block > 0);
  655.     }
  656.     else
  657.     IritPrsrFatalError("Invalid communication handler");
  658.  
  659.     if (PObj == NULL)
  660.     PObj = GenSTRObject("No data (timeout)");
  661.  
  662.     return PObj;
  663. }
  664.  
  665. /*****************************************************************************
  666. * DESCRIPTION:                                                               M
  667. *   Writes one object to subprocess's output channel specified by Handler.   M
  668. *                                                                            *
  669. * PARAMETERS:                                                                M
  670. *   RHandler:  Valid subprocess handler.                                     M
  671. *   PObj:      Object to write.                                              M
  672. *                                                                            *
  673. * RETURN VALUE:                                                              M
  674. *   void                                                                     M
  675. *                                                                            *
  676. * KEYWORDS:                                                                  M
  677. *   ClientWrite, ipc                                                         M
  678. *****************************************************************************/
  679. void ClientWrite(RealType *RHandler, IPObjectStruct *PObj)
  680. {
  681.     int Handler = REAL_PTR_TO_INT(RHandler);
  682.  
  683.     if (Handler >= 0 &&
  684.     Handler < MAX_NUM_OF_IO_HANDLES &&
  685.     IOHandles[Handler].InUse) {
  686.     SocWriteOneObject(IOHandles[Handler].Input, PObj);
  687.     }
  688.     else
  689.     IritPrsrFatalError("Invalid communication handler");
  690. }
  691.  
  692.